<template>
    <!-- 收货地址 -->
    <van-contact-card type="edit" :name="`${address.consignee} ${address.region_text}`" :tel="address.mobile" @click="AddressShow = true" />

    <!-- 物流公司 -->
    <van-field
        label="物流公司"
        v-model="order.name"
        readonly
    />

    <van-field
        label="物流单号"
        v-model="order.code"
        readonly
    />

    <van-field
        label="物流状态"
        v-model="order.status"
        readonly
    />

    <!-- 物流进度 -->
    <van-steps v-if="express.length > 0" direction="vertical" :active="0">
        <van-step v-for="item in express" :key="item.time">
            <h3>{{item.status}}</h3>
            <p>{{item.time}}</p>
        </van-step>
    </van-steps>

</template>

<script setup>
const { proxy } = getCurrentInstance();

// 用户信息
const business = proxy.$business;
const orderid = ref(proxy.$route.query.orderid ?? 0);

// 用户收货地址的相关变量
const address = ref({});
const AddressShow = ref(false);

// 订单信息
const order = ref({});

// 物流信息
const express = ref([]);

onBeforeMount(() => GetExpressInfo());

// 获取物流详情和订单信息
const GetExpressInfo = async () =>
{
    // 封装请求参数
    const params = {
        busid:business.value.id,
        orderid:orderid.value
    }

    const result = await proxy.$http.post({
        url:'/order/express',
        params
    });

    if(result.code === 1)
    {
        address.value = result.data.address;
        order.value = {
            name:result.data.order.express.name,
            code:result.data.order.expresscode,
            status:result.data.order.status_text
        }
        express.value = result.data.express;
    }else{
        proxy.$fail(result.msg,() => proxy.$router.back());
    }
}
</script>